package com.chushouya.product.dto.admin.evaluate;

import com.chushouya.common.util.ProductUtil;
import com.general.framework.core.lang.Lists;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

@Data
@ApiModel("API-估价结果")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class EvaluateResultDTO {

    // base

    @ApiModelProperty("估价id")
    private Long evaluateLogId;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty("估价id")
    private Long evaluateId;

    @ApiModelProperty("平台")
    private String platform;

    @ApiModelProperty("渠道")
    private String channel;

    @ApiModelProperty("合作商ID")
    private Long partnerId;


    // product and sku

    @ApiModelProperty("商品ID")
    private Long productId;

    @ApiModelProperty("商品名称")
    private String productName;

    @ApiModelProperty("商品图片")
    private String productImage;

    @ApiModelProperty("skuId")
    private Long skuId;

    @ApiModelProperty("sku名称")
    private String skuName;

    @ApiModelProperty("SKU组合码")
    private String skuAttrCode;

    @ApiModelProperty("SKU组合码")
    private List<SkuAttrDTO> skuAttrs;

    @ApiModelProperty("SKU评估基础价格")
    private BigDecimal basePrice;

    @ApiModelProperty("SKU最低回收价")
    private BigDecimal minPrice;

    @ApiModelProperty("SKU最高回收价")
    private BigDecimal maxPrice;


    // category brand series

    @ApiModelProperty("商品分类")
    private Long categoryId;

    @ApiModelProperty("商品分类")
    private String categoryName;

    @ApiModelProperty("商品品牌")
    private Long brandId;

    @ApiModelProperty("商品品牌")
    private String brandName;

    @ApiModelProperty("商品系列")
    private Long seriesId;

    @ApiModelProperty("商品系列")
    private String seriesName;


    // output

    @ApiModelProperty("评估价格")
    private BigDecimal evaluatePrice;

    @ApiModelProperty("下周下跌价格")
    private BigDecimal nextWeekFallPrice;

    @ApiModelProperty("评估选项")
    private List<Long> selectSkuItemValueIds;

    @ApiModelProperty("评估项目与选项")
    private List<EvaluateItemAndValue> evaluateItems = Lists.newArrayList();

    @ApiModelProperty("扣减方式")
    private Integer calcType;

    @ApiModelProperty("估价扣减详情")
    private List<EvaluateRuleDTO> evaluateRules = Lists.newArrayList();

    @ApiModelProperty("是否为新机")
    private Boolean isNewMachine = Boolean.FALSE;


    public void addEvaluateRule(EvaluateRuleDTO rule){
        if (Objects.nonNull(rule)) {
            this.evaluateRules.add(rule);
        }
    }

    public BigDecimal getNextWeekFallPrice() {
        return ProductUtil.getNextWeekFallPrice(this.maxPrice);
    }

}
